package com.zf.yichat.api.controller.app;

import com.alibaba.fastjson.JSONArray;
import com.zf.yichat.api.controller.BaseController;
import com.zf.yichat.api.dto.request.RYunReceiveMessageRequest;
import com.zf.yichat.api.dto.resp.RYunReceiveMessageDto;
import com.zf.yichat.model.SysDict;
import com.zf.yichat.service.SysDictService;
import com.zf.yichat.utils.response.FsResponse;
import com.zf.yichat.utils.response.FsResponseGen;
import com.zf.yichat.vo.DictKey;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.util.TextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
@RequestMapping("app")
@Slf4j
public class AppController extends BaseController {

    @Autowired
    private SysDictService sysDictService;

    @PostMapping("/serverlist")
    public FsResponse version() {
         String sysDicServerList=   Optional.ofNullable(sysDictService.selectOne(DictKey.sys_dict_server_list)).map(SysDict::getMemo).orElse("");
        JSONArray jsonArray=new JSONArray();
        if(!TextUtils.isEmpty(sysDicServerList)){
           String[]  listData=sysDicServerList.split("#");
           for(String serverName:listData){
                jsonArray.add(serverName.trim());
           }
        }

        return FsResponseGen.successData(jsonArray);
    }


    /**
     * 融云回调服务接口
     * @return
     */
    @RequestMapping("/rYunReceiveMessage")
    @ResponseBody
    public RYunReceiveMessageDto rYunReceiveMessage(RYunReceiveMessageRequest request) {
        RYunReceiveMessageDto dto = new RYunReceiveMessageDto();
        dto.setPass(0);
        dto.setCode(200);
        return dto;
    }

}
